package com.comp490.bullet;

import android.graphics.Canvas;

import com.comp490.shooter.GameView;
import com.comp490.sprite.Ship;

public class RectangularBullet extends Bullet
{
    private int width;
    private int height;

    public RectangularBullet(float x, float y, int damage, int width,
            int height, boolean active)
    {
        super(x, y, damage, active);
        this.width = width;
        this.height = height;
        radius = height < width ? height : width;
    }

    public boolean boundsCheck(GameView g)
    {
        return x > -width / 2 && x < g.getWidth() + width / 2;
    }

    public boolean collisionCheck(Ship object)
    {
        if(!active)
            return false;
        float dx = x - object.getCenterBitmapX();
        float dy = y - object.getCenterBitmapY();
        return android.util.FloatMath.sqrt(dx * dx + dy * dy) < radius
                + object.collisionRadius();
    }

    public void draw(Canvas c)
    {
        if(active)
            c.drawRect(x - width, y - height, x + width, y + height, paint);
    }

    public float collisionRadius()
    {
        return radius;
    }
}